#include<bits/stdc++.h>

using namespace std;
using i64 = long long;

int read() {
	int x = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
	return x;
}
const int N = 1e5 + 10;
int n;
struct node {
	int x, y;
	bool operator <(const node &b) const {
		return y < b.y;
	}
}a[N];
multiset<i64> s, t;
i64 ans = 1e18;
int main() {
	freopen("boast.in", "r", stdin);
	freopen("boast.out", "w", stdout);
	n = read();
	for (int i = 1; i <= n; ++i) 
		a[i].x = read(), a[i].y = read();
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; ++i) t.insert(a[i].x + a[i].y);
	for (int i = 1; i <= n; ++i) {
		t.erase(a[i].x + a[i].y);
		if ((int)s.size() >= 2) ans = min(ans, (*s.begin()) + (*(++s.begin())) + 2 * a[i].y + a[i].x);
		if ((int)t.size() >= 2) ans = min(ans, (*t.begin()) + (*(++t.begin())) + a[i].x);
		if (!s.empty() && !t.empty()) ans = min(ans, (*s.begin()) + a[i].y + (*t.begin()) + a[i].x);
		s.insert(a[i].x);
	}
	cout << ans;
	return 0;
}

